package com.leesche.zcsp.node.app.v1.timer;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: PhoneCodeCacheTimer.java
 * @Description: TODO( 手机短信验证码定时器 )
 * @author Jerry Chan
 * @date 2016/12/8 15:51
 * @version V1.0
 * ************ * Jerry Chan: * 2016/12/8 15:51: * 创建该类并实现业务逻辑: *********
 */
@Component
@Lazy(value = false)
public class PhoneCodeCacheTimer {

    private final static Logger LOGGER = Logger.getLogger(PhoneCodeCacheTimer.class);
    //手机验证码
    private static Map<String,VaildPhone> phone_code = new HashMap<String, VaildPhone>();

    public synchronized static VaildPhone get(String key){
       return phone_code.get(key);
    }

    public synchronized static void put(String key,VaildPhone value){
        phone_code.put(key,value);
    }

    public synchronized static void remove(String key){
        phone_code.remove(key);
    }

    public synchronized static void clear(){
        phone_code.clear();
    }

    /**
     * @Title:  doPhoneCodeTimer
     * @Description: TODO( 每隔30分钟清空一次内存中的手机验证码 )
     * @author Jerry Chan
     * @date 2016/11/29 17:50
     * @return
     */

    @Scheduled(fixedRate = 1000 * 60 * 30)
    private void doPhoneCodeTimer(){
        LOGGER.info("清空内存中的短信验证码---> 开始");
        this.clear();
        LOGGER.info("清空内存中的短信验证码---> 结束");
    }

}
